<?php

namespace app\admin\controller;

use think\Controller;
use think\Db;

class Othvideo extends Controller
{
    public function __construct()
    {
        parent::__construct();
        if(!session('name')){
            $this->redirect("/admin/login/login");
        }
    }
    public function index(){
        $videoList=Db::name('othvideo')->order('othvideo_creat_time desc')->select();
        $this->assign('videoList',$videoList);
        return $this->fetch();
    }
    public function add(){
        if(request()->isPost()){
            $video=input('param.');
            $video['othvideo_creat_time']=time();
            $check=(new \app\common\model\Othvideo())->checkName($video);
            if($check){
                $res=(new \app\common\model\Othvideo())->allowField(true)->save($video);
                if($res){
                    return $this->success("视频添加成功",'admin/othvideo/index');
                }else{
                    return $this->error("视频添加失败");
                }
            }else{
                return $this->error("视频名称已使用，请更换");
            }
        }
        return $this->fetch();
    }
    public function delete(){
        $videoId=input('param.id');
        $res=Db::name('othvideo')->where('othvideo_id',$videoId)->delete();
        if($res){
            return $this->success("视频删除成功");
        }else{
            return $this->error("视频删除失败");
        }
    }
}
